import 'package:flutter/material.dart';
import 'package:flutter_demo/chapter8-EventNotification/event-mechanism/HitTestBlocker.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text("Event Widget Demo"),
      ),
      body: StackEventWidget(),
    ),
  ));
}

class StackEventWidget extends StatelessWidget {
  const StackEventWidget({Key? key}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        // 不会再对子组件进行命中测试，这意味着它的子组件树也将不能响应事件
        HitTestBlocker(child: wChild(1),),
        HitTestBlocker(child: wChild(2),),
      ],
    );
  }

  wChild(int index) {
    return Listener(
      // behavior: HitTestBehavior.opaque, // 放开此行，点击只会输出 2
      behavior: HitTestBehavior.translucent, // 放开此行，点击会同时输出 2 和 1
      onPointerDown: (e) => print(index),
      child: GestureDetector(
        onTap: () => print('$index'),
        child: Container(
          width: 100,
          height: 100,
          color: Colors.grey,
          child: SizedBox.expand(),
        ),
      ),
    );
  }
}
